import {mainStore} from '../store';
import { ref,reactive, watch } from "vue";
import axios from "axios";

//仔细上面代码， permission.ts 在全局store还没有挂载到app上的时候，就引入进来了，这时候里面useStore在全局代码下就调用了，这样导致了pinia实例还没挂载。
//export const store = mainStore();

export let roomID = ref<number>(); 
interface Medal{//粉丝排
    leavel:number, //牌子等级
    fansUp:string,//牌子的up主牌子名字
    fansUpName:string,//牌子up主名字
    one:number,
    two:number,
    three:string,
    four:number,
    five:number,
    six:number,
    seven:number,
    eight:number,
    nine:number,
    ten:number
}
interface DMMsg{
    text:string,//发送的弹幕信息
    nickname:string,//发送者的名称
}

//房管弹幕
export let admin = reactive<DMMsg>({
    text: '' as string,
    nickname: '' as string
})

//用户弹幕
export let room = reactive<DMMsg>({
    text: '' as string,
    nickname: '' as string
})

export let adminArray = reactive<Array<DMMsg>>([
    {
      text: '' as string,
      nickname: '' as string
    },
    {
      text: '' as string,
      nickname: '' as string
    },
    {
      text: '' as string,
      nickname: '' as string
    },
    {
      text: '' as string,
      nickname: '' as string
    },
    {
      text: '' as string,
      nickname: '' as string
    },
    {
      text: '' as string,
      nickname: '' as string
    },
    {
      text: '' as string,
      nickname: '' as string
    },
    {
      text: '' as string,
      nickname: '' as string
    },
    {
      text: '' as string,
      nickname: '' as string
    },
    {
      text: '' as string,
      nickname: '' as string
    }
  ])
  //判断是否显示
export let show = ref<boolean>(false);
export let roomArray = reactive<Array<DMMsg>>([
    {
      text: '' as string,
      nickname: '' as string
    },
    {
      text: '' as string,
      nickname: '' as string
    },
    {
      text: '' as string,
      nickname: '' as string
    },
    {
      text: '' as string,
      nickname: '' as string
    },
    {
      text: '' as string,
      nickname: '' as string
    },
    {
      text: '' as string,
      nickname: '' as string
    },
    {
      text: '' as string,
      nickname: '' as string
    },
    {
      text: '' as string,
      nickname: '' as string
    },
    {
      text: '' as string,
      nickname: '' as string
    },
    {
      text: '' as string,
      nickname: '' as string
    }
  ])

export function getLiveRoomForAxios(roomID:number){
    const store = mainStore();
    show.value = true;
    axios.get(`/api/getBiliLiveRoom?roomid=${roomID}`).then(res=>{
        console.log(res)
        for(var i=0;i<res.data.data.admin.length;i++){
            adminArray[i].text = res.data.data.admin[i].text;
            adminArray[i].nickname = res.data.data.admin[i].nickname;
        }
        for(var i=0;i<res.data.data.room.length;i++){
            roomArray[i].text = res.data.data.room[i].text;
            roomArray[i].nickname = res.data.data.room[i].nickname;
        }
    })
}




